package com.ydgk.jishuzhan.service.impl;

import com.ydgk.jishuzhan.beans.Question;
import com.ydgk.jishuzhan.beans.QuestionCollection;
import com.ydgk.jishuzhan.dao.QuestionMapper;
import com.ydgk.jishuzhan.dao.UserMapper;
import com.ydgk.jishuzhan.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionMapper questionMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public void save(Question question) {
        questionMapper.save(question);
    }

    @Override
    public List<Question> findQuestions() {
        List<Question> questions = questionMapper.findAll();
        List<Question> questions1=new ArrayList<>();
        for (Question question:questions){
            question.getQuestionInfo().setUser(userMapper.findUserById(question.getUserId()));
            questions1.add(question);
        }
        return questions1;
    }

    @Override
    public Question findQuestion(Integer id) {
        return questionMapper.findById(id);
    }

    @Override
    public List<Question> findQuestionsById(Integer id) {
        return questionMapper.findQuestionsById(id);
    }

    @Override
    public int findCollection(Integer userId, Integer questionId) {
        return questionMapper.findCollection(userId,questionId);
    }

    @Override
    public void collectionAdd(Integer userId, Integer questionId) {
        questionMapper.collectionAdd(userId,questionId);
    }

    @Override
    public int findCollections(Integer id) {
        return questionMapper.findCollections(id);
    }

    @Override
    public List<QuestionCollection> getCollections(Map<String, Object> map) {
        return questionMapper.getCollections(map);
    }

    @Override
    public Integer queryQuestionTotal(Map<String, Object> map) {
        return questionMapper.queryQuestionTotal(map);
    }

    @Override
    public void deleteQCollection(Integer id) {
        questionMapper.deleteQCollection(id);
    }
}
